from fastapi import APIRouter
from ..services import (
    wikidata_by_qid_service, 
    wikidata_sparql_service,
)

router = APIRouter()

@router.get("/query/by-qid", tags=["wikidata"])
async def get_wikidata_entity_by_qid(qid:str,  cache_ttl:int=60*60*24*365):
    return await wikidata_by_qid_service.submit_task(qid, cache_ttl)

query = f"""
SELECT ?subClass ?subClassLabel
WHERE {{
    ?subClass wdt:P279 wd:Q43229.
    SERVICE wikibase:label {{ bd:serviceParam wikibase:language "en,ceb,de,fr,sv,nl,ru,es,it,pl,arz,ja,vi,war,zh,ar,uk,pt,fa,ca". }}
}}
ORDER BY ?subClassLabel
"""

@router.get("/sparql", tags=["wikidata"])
async def get_wikidata_sparql(query:str=query,  cache_ttl:int=60*60*24*365):
    return await wikidata_sparql_service.submit_task(query, cache_ttl)
